/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package library;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author mr2
 */
public class NamaLab {
    
    Connection koneksi;
    String namaLab;
    
    public NamaLab(){
        koneksi = Koneksi.getKoneksi();
    }

    public String getNamaLab() {
        return namaLab;
    }

    public void setNamaLab(String namaLab) {
        this.namaLab = namaLab;
    }
    
    public List<NamaLab> ListLab (){
        
        PreparedStatement prepare = null;
        ResultSet result = null;
        List<NamaLab> listLab = new ArrayList<NamaLab>();
        
        try{
            String sql = "SELECT * FROM lab";
            
            prepare = koneksi.prepareStatement(sql);
            
            result = prepare.executeQuery();
            
            while(result.next()){
                NamaLab lab = new NamaLab();
                lab.setNamaLab(result.getString("nama_lab"));
                
                listLab.add(lab);
            }
            return listLab;
            
        }catch(SQLException ex){
            System.out.print(ex.getMessage());
            return listLab;            
        }finally{
            if(prepare != null){
                try{
                    prepare.close();
                }catch(SQLException ex){
                    
                }
            }
            if(result != null){
                try{
                    result.close();
                }catch(SQLException ex){
                    
                }
            }
        }
    } 
    
}
